Skip to content

fix: create missing output directories for GPX and event exports (#26)#28

Merged
nerdCopter merged 2 commits into
masterfrom
20251213_FIX_ISSUE_26
Dec 13, 2025
Merged

fix: create missing output directories for GPX and event exports (#26)#28
nerdCopter merged 2 commits into
masterfrom
20251213_FIX_ISSUE_26

Conversation

@nerdCopter
Copy link
Copy Markdown
Owner

@nerdCopter nerdCopter commented Dec 13, 2025

Fixes issue #26: The GPX and event export functions failed when export_options.output_dir pointed to a non-existent directory. This PR mirrors the behavior of export_to_csv() by adding std::fs::create_dir_all() to export_to_gpx() and export_to_event() before attempting to create files.

Changes

Bug fix:

  • Adds output directory creation to export_to_gpx() and export_to_event()
  • Includes comments explaining the behavior and matching CSV logic

Refactor (reduces duplication):

  • Both functions now use compute_export_paths() for consistent naming with CSV exports
  • Eliminates duplicate filename construction logic (.NN suffix and extensions)
  • Ensures naming scheme stays in sync across all export formats

Testing

  • All tests pass (26 library + 11 main tests)
  • Clippy and formatting checks pass
  • Release build successful

Resolves: #26

Summary by CodeRabbit

  • Bug Fixes
    • Exporting to GPX and event formats now creates missing output directories automatically, preventing export failures and matching CSV behavior.
  • Refactor
    • Export path construction was centralized for more consistent and reliable output file handling while preserving existing export outputs.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add std::fs::create_dir_all() to export_to_gpx before file creation
- Add std::fs::create_dir_all() to export_to_event before file creation
- Both functions now match export_to_csv behavior for directory handling
- Fixes issue where exports to non-existent directories would fail with ENOENT

Resolves: #26
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 13, 2025

📝 Walkthrough

Walkthrough

Replaced manual path construction in GPX and Event exports with compute_export_paths(...), updated file creation to use those paths, and added directory creation for computed output parents before writing (in src/export.rs).

Changes

Cohort / File(s) Summary
Export path centralization & directory creation
src/export.rs
Replaced manual base name / suffix / output-dir assembly in export_to_gpx and export_to_event with compute_export_paths(...); ensure parent directories exist via std::fs::create_dir_all(...) before creating files; updated file creation calls to use computed paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Single file changed but includes logic relocation (path computation) and I/O behavior change (directory creation).
  • Review focus: correctness of compute_export_paths usage, preservation of existing naming/suffix semantics, and error handling for directory creation and file writes.

Possibly related issues

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: creating missing output directories for GPX and event exports, directly addressing the core bug fix.
Linked Issues check ✅ Passed The PR addresses the primary bug fix (adding directory creation to GPX and event exports) by centralizing path logic with compute_export_paths. The optional refactoring suggestion is a lower-priority DRY improvement that was not fully implemented.
Out of Scope Changes check ✅ Passed All changes directly relate to the issue objectives: refactoring path computation into compute_export_paths and ensuring output directories exist before file creation, with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 20251213_FIX_ISSUE_26

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c67a8e8 and 837c298.

📒 Files selected for processing (1)
  • src/export.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.rs: Do not remove or modify comments unless the related code is changed
Only add comments that explain code functionality; no AI instructional comments
Never embed or call external binaries from Rust code
Ensure cargo build --release has no errors or warnings
Only commit if cargo clippy --all-targets --all-features -- -D warnings passes
Only commit if cargo fmt --all -- --check passes
Only commit if cargo test --verbose passes
Only commit if cargo build --release passes with no errors or warnings
BEFORE ANY CODE CHANGES: Always run cargo clippy --all-targets --all-features -- -D warnings to catch ALL issues
BEFORE ANY CODE CHANGES: Always run cargo fmt --all -- --check to ensure formatting compliance
If cargo fmt --all -- --check fails, IMMEDIATELY run cargo fmt --all to fix formatting
Code must pass cargo fmt --all -- --check without any formatting issues
Never skip clippy checks or formatting checks. Never allow warnings to pass
ALWAYS run cargo fmt --all after making ANY code changes before moving to next steps
After running cargo fmt --all, ALWAYS verify with cargo fmt --all -- --check before proceeding

Files:

  • src/export.rs
src/{parser/**/*.rs,export.rs}

📄 CodeRabbit inference engine (AGENTS.md)

Parser modules should be placed in src/parser/ and export functions in src/export.rs for sharing between library and CLI

Files:

  • src/export.rs
src/{export.rs,lib.rs}

📄 CodeRabbit inference engine (AGENTS.md)

The CSV output must precisely match the format and header order of blackbox_decode CSV files

Files:

  • src/export.rs
{src/**/*.rs,Cargo.toml}

📄 CodeRabbit inference engine (AGENTS.md)

{src/**/*.rs,Cargo.toml}: Only commit if cargo test --features=cli --verbose passes
All feature combinations must compile without errors

Files:

  • src/export.rs
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/main.rs : CLI (`src/main.rs`) should use library export functions (`export_to_csv`, `export_to_gpx`, `export_to_event`) with CLI-specific status messages
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/lib.rs : Public API must expose: `parse_bbl_file()`, `parse_bbl_bytes()`, `BBLLog`, `ExportOptions`, `export_to_csv()`, `export_to_gpx()`, `export_to_event()`, conversion utilities, parser helpers
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: LICENSE_COMMERCIAL:1-4
Timestamp: 2025-08-29T19:52:05.099Z
Learning: nerdCopter prefers to avoid publishing personal information in license files for privacy and security reasons, as they are an individual maintainer rather than a company.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: README.md:520-521
Timestamp: 2025-08-29T19:53:41.354Z
Learning: nerdCopter uses AGPL-3.0-or-later licensing for the bbl_parser project with a dual-licensing approach that includes a separate commercial license option.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: CONTRIBUTING.md:9-14
Timestamp: 2025-08-21T20:25:45.741Z
Learning: nerdCopter prefers to keep CLA language general using "project maintainer" rather than specifying a legal entity name, as they are an individual maintainer without an associated company.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: LICENSE_COMMERCIAL:0-0
Timestamp: 2025-08-29T20:15:04.624Z
Learning: nerdCopter prefers clear positive indicators (✅) when describing fixes rather than using ❌ symbols which can be confusing when describing what was corrected in a positive context.
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/main.rs : CLI (`src/main.rs`) should use library export functions (`export_to_csv`, `export_to_gpx`, `export_to_event`) with CLI-specific status messages

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/lib.rs : Public API must expose: `parse_bbl_file()`, `parse_bbl_bytes()`, `BBLLog`, `ExportOptions`, `export_to_csv()`, `export_to_gpx()`, `export_to_event()`, conversion utilities, parser helpers

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{parser/**/*.rs,export.rs} : Parser modules should be placed in `src/parser/` and export functions in `src/export.rs` for sharing between library and CLI

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{export.rs,lib.rs} : The CSV output must precisely match the format and header order of blackbox_decode CSV files

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{main,lib}.rs : Core logic in `src/lib.rs` and CLI entry point in `src/main.rs`

Applied to files:

  • src/export.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build Release Binaries (macos-latest, bbl_parser-macos-x64, target/release/bbl_parser)
  • GitHub Check: Build Release Binaries (ubuntu-latest, bbl_parser-linux-x64, target/release/bbl_parser)
  • GitHub Check: Build Release Binaries (windows-latest, bbl_parser-windows-x64, target/release/bbl_parser.exe)
🔇 Additional comments (2)
src/export.rs (2)

372-383: Excellent fix - addresses issue #26 and improves code consistency.

The changes correctly:

  1. Use compute_export_paths for centralized naming logic (avoiding duplication)
  2. Create output directories before file creation (mirroring export_to_csv behavior)
  3. Convert 0-based log_index to 1-based for compute_export_paths
  4. Use defensive if let Some(parent) pattern for safety

The directory creation now matches the CSV export pattern and ensures GPX exports work when export_options.output_dir points to a non-existent path.


432-443: Excellent - consistent implementation matching GPX export fix.

The event export now:

  1. Uses compute_export_paths for consistent naming across all export types
  2. Creates output directories before file creation
  3. Properly converts log_index to 1-based log number
  4. Handles edge cases defensively with if let Some(parent)

This ensures event exports work correctly when the output directory doesn't exist, completing the fix for issue #26.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/export.rs (1)

386-391: Optional: Consider using compute_export_paths to reduce duplication.

Both export_to_gpx and export_to_event duplicate the filename construction logic (suffix and extension patterns) that's already implemented in compute_export_paths(). As noted in the PR objectives, this is a lower-priority refactor that could reduce duplication and ensure naming consistency.

Also applies to: 456-461

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65b64cc and c67a8e8.

📒 Files selected for processing (1)
  • src/export.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.rs: Do not remove or modify comments unless the related code is changed
Only add comments that explain code functionality; no AI instructional comments
Never embed or call external binaries from Rust code
Ensure cargo build --release has no errors or warnings
Only commit if cargo clippy --all-targets --all-features -- -D warnings passes
Only commit if cargo fmt --all -- --check passes
Only commit if cargo test --verbose passes
Only commit if cargo build --release passes with no errors or warnings
BEFORE ANY CODE CHANGES: Always run cargo clippy --all-targets --all-features -- -D warnings to catch ALL issues
BEFORE ANY CODE CHANGES: Always run cargo fmt --all -- --check to ensure formatting compliance
If cargo fmt --all -- --check fails, IMMEDIATELY run cargo fmt --all to fix formatting
Code must pass cargo fmt --all -- --check without any formatting issues
Never skip clippy checks or formatting checks. Never allow warnings to pass
ALWAYS run cargo fmt --all after making ANY code changes before moving to next steps
After running cargo fmt --all, ALWAYS verify with cargo fmt --all -- --check before proceeding

Files:

  • src/export.rs
src/{parser/**/*.rs,export.rs}

📄 CodeRabbit inference engine (AGENTS.md)

Parser modules should be placed in src/parser/ and export functions in src/export.rs for sharing between library and CLI

Files:

  • src/export.rs
src/{export.rs,lib.rs}

📄 CodeRabbit inference engine (AGENTS.md)

The CSV output must precisely match the format and header order of blackbox_decode CSV files

Files:

  • src/export.rs
{src/**/*.rs,Cargo.toml}

📄 CodeRabbit inference engine (AGENTS.md)

{src/**/*.rs,Cargo.toml}: Only commit if cargo test --features=cli --verbose passes
All feature combinations must compile without errors

Files:

  • src/export.rs
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/main.rs : CLI (`src/main.rs`) should use library export functions (`export_to_csv`, `export_to_gpx`, `export_to_event`) with CLI-specific status messages
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/lib.rs : Public API must expose: `parse_bbl_file()`, `parse_bbl_bytes()`, `BBLLog`, `ExportOptions`, `export_to_csv()`, `export_to_gpx()`, `export_to_event()`, conversion utilities, parser helpers
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{parser/**/*.rs,export.rs} : Parser modules should be placed in `src/parser/` and export functions in `src/export.rs` for sharing between library and CLI
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{export.rs,lib.rs} : The CSV output must precisely match the format and header order of blackbox_decode CSV files
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: LICENSE_COMMERCIAL:1-4
Timestamp: 2025-08-29T19:52:05.099Z
Learning: nerdCopter prefers to avoid publishing personal information in license files for privacy and security reasons, as they are an individual maintainer rather than a company.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: README.md:520-521
Timestamp: 2025-08-29T19:53:41.354Z
Learning: nerdCopter uses AGPL-3.0-or-later licensing for the bbl_parser project with a dual-licensing approach that includes a separate commercial license option.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: CONTRIBUTING.md:9-14
Timestamp: 2025-08-21T20:25:45.741Z
Learning: nerdCopter prefers to keep CLA language general using "project maintainer" rather than specifying a legal entity name, as they are an individual maintainer without an associated company.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: LICENSE_COMMERCIAL:0-0
Timestamp: 2025-08-29T20:15:04.624Z
Learning: nerdCopter prefers clear positive indicators (✅) when describing fixes rather than using ❌ symbols which can be confusing when describing what was corrected in a positive context.
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/main.rs : CLI (`src/main.rs`) should use library export functions (`export_to_csv`, `export_to_gpx`, `export_to_event`) with CLI-specific status messages

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/lib.rs : Public API must expose: `parse_bbl_file()`, `parse_bbl_bytes()`, `BBLLog`, `ExportOptions`, `export_to_csv()`, `export_to_gpx()`, `export_to_event()`, conversion utilities, parser helpers

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{parser/**/*.rs,export.rs} : Parser modules should be placed in `src/parser/` and export functions in `src/export.rs` for sharing between library and CLI

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{export.rs,lib.rs} : The CSV output must precisely match the format and header order of blackbox_decode CSV files

Applied to files:

  • src/export.rs
📚 Learning: 2025-12-13T15:51:00.125Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-13T15:51:00.125Z
Learning: Applies to src/{main,lib}.rs : Core logic in `src/lib.rs` and CLI entry point in `src/main.rs`

Applied to files:

  • src/export.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test (windows-latest)
🔇 Additional comments (2)
src/export.rs (2)

380-384: Directory creation fix looks good.

The added logic correctly ensures the output directory exists before writing the GPX file, matching the export_to_csv behavior and resolving issue #26.


450-454: Directory creation fix looks good.

The added logic correctly ensures the output directory exists before writing the event file, matching the export_to_csv behavior and resolving issue #26.

…aming

- Replace duplicate filename construction logic in export_to_gpx and export_to_event
- Both functions now use compute_export_paths() for consistent naming with CSV exports
- Reduces code duplication and improves maintainability
- Ensures naming scheme stays in sync across all export formats

Related to: #26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

src/export.rs: GPX export missing directory creation + code reuse opportunity

1 participant